class Solution {
public:
    string compressString(string S)
    {
        string s;
    int i = 0, j = 0, g = 1,sh=0;
    while (i < S.size())
    {
        s += S[i];
        for (j = i + 1;j < S.size()+1;j++)
        {
            if (S[i] == S[j])
            {
                g++;
            }
            else
            {
                string s1;
                while(g>=10)
                {
                    sh = g%10;
                    char cc =sh+'0';
                    s1+=cc;
                    g/=10;
                }
                s1+=g+'0';
                reverse(s1.begin(),s1.end());
                s+=s1;
                g=1;
                break;
            }   
        }
        i = j;
    }
    if (s.size() >= S.size())
    {
        return S;
    }

    return s;

    }
};